package com.wang.learn.postgres.service;

import com.wang.learn.postgres.entity.Book;
import com.wang.learn.postgres.repository.BookRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Wang
 * @description
 * @create 2022-02-20 13:41
 */
@Service
public class BookService {

    final BookRepository bookRepository;

    public BookService(BookRepository bookRepository) {
        this.bookRepository = bookRepository;
    }


    @Transactional(rollbackFor = Exception.class)
    public Book createBook(Book book) {
        return bookRepository.save(book);
    }

    @Transactional(readOnly = true)
    public List<Book> findAll(Book book) {
        return bookRepository.findAll();
    }



}
